package control_package;

import Entitys.Persona;
import boundary_package.MainFrame;
import services.PersonaServices;



// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.59969228-2F45-84CB-BA60-B1F0BB6466B2]
// </editor-fold> 
public class RegisterControl {
        PersonaServices perS=new PersonaServices();
    
    
//    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
//    // #[regen=yes,id=DCE.3E7A0EC2-21C7-7672-EE83-2798CDB23D4E]
//    // </editor-fold> 
    public String makeRegister (Persona persona) {
        if(!verifyIdentification(persona)){
            return "Cédula ya registrada";
        }
        if(!verifyEmail(persona)){
            return "Correo ya existente porfavor ingrese otro";
        }
        if(!verifyNameLength(persona.getNombrePersona(),persona.getApellidoPersona())){
            return "Nombre o apellido invalido";
        }
        if(!verifyPassword(persona.getPassPersona())){
        return "contraseña inválida";    
        }
        perS.create(persona);
        return "Registro Hecho";
        
    }

//    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
//    // #[regen=yes,id=DCE.AB477609-AAC7-A4A2-EBE6-519079B0886E]
//    // </editor-fold> 
    public boolean verifyEmail (Persona p) {
        for(Persona u:perS.ReadAll(MainFrame.DrugPresent.getIdDrogueria())){
            if(p.getMailPersona().equals(u.getMailPersona())){
             return false;
            }
        }
        
        return true;
    }
    
    public boolean verifyIdentification (Persona p) {
        for(Persona u:perS.ReadAll(MainFrame.DrugPresent.getIdDrogueria())){
            if(p.getIdPersona().equals(u.getIdPersona())){
             return false;
            }
        }
        
        return true;
    }
    
    public boolean verifyNameLength(String fN,String lN){
        if(fN.length()>1 && fN.length()<=20 && lN.length()>1 && lN.length()<=20){
          return true;
        }
        return false;
    }

    public boolean verifyPassword(String pass){
        if(pass.length()>5 && pass.length()<=12){
          return true;
        }
        return false;
    }
//    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
//    // #[regen=yes,id=DCE.97B9D3C4-AA9F-2C28-7413-5224D3D09125]
//    // </editor-fold> 
//    public Boolean UserCorrect (int rol) {
//        return null;
//    }

}

